﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Content/Master.Master" Inherits="System.Web.Mvc.ViewPage<SCS.Core.Models.Collection.DiscountCollection>" %>
<%@ Import Namespace="SCS.Core" %>
<%@ Import Namespace="SCS.Core.Models" %>
<%@ Import Namespace="SCS.Core.ViewModels" %>
<%@ Import Namespace="SCS.Core.Controllers" %>
<%@ Import Namespace="SCSService" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Chi tiết triết khấu
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <link rel="stylesheet" type="text/css" href="/Content/smoothness-1.8.13/jquery-ui-1.8.13.custom.css">
    <link rel="stylesheet" type="text/css" href="/Content/smoothness-1.8.13/ui.dropdownchecklist.themeroller.css">
    <script type="text/javascript" src="/Scripts/jquery-1.6.1.min.js"></script>
    <script type="text/javascript" src="/Scripts/jquery-ui-1.8.13.custom.min.js"></script>
    <script type="text/javascript" src="/Scripts/ui.dropdownchecklist-1.4-min.js"></script>
    <script src="/Scripts/jquery.selectboxes.min.js" type="text/javascript"></script>
    <%--Validator--%>
    <script src="/Scripts/jquery.validate.min.js" type="text/javascript"></script>
    <script src="/Scripts/MicrosoftMvcJQueryValidation.js" type="text/javascript"></script>
    <script type="text/javascript">
            function getProduct(id) {
                $.ajax({
                   type: "POST",
                   url: '<%=Url.Action("GetListProductByListType","Stock")%>' + '/' + id,
                   contentType: "application/json; charset=utf-8",
                   dataType: "json",
                   success: function (listresult) {
                       $('#ddcl-ProductDrop').remove();
                       $('#ddcl-ProductDrop-ddw').remove();
                    
                       $('#ProductDrop').removeOption(/./);
                       for (var i = 0; i < listresult.length; i++) {
                           var val = listresult[i].split("|")[0];
                           var text = listresult[i].split("|")[1];
                           $('#ProductDrop').addOption(val, text, false);
                       }

                       $("#ProductDrop").dropdownchecklist({ icon: {}, width: 350, explicitClose: '...X', forceMultiple: true
                        , onComplete: function (selector) {
                            var values = "";
                            for (i = 0; i < selector.options.length; i++) {
                                if (selector.options[i].selected && (selector.options[i].value != "")) {
                                    if (values != "") values += ",";
                                    values += selector.options[i].value;
                                }
                            }

                            if (document.all || document.getElementById) {
                                document.getElementById('ArrProductID').value = values;
                            }
                            else {
                                document.getElementById('ArrProductID').setAttribute("value", values);
                            }
                        }
                        , onItemClick: function (checkbox, selector) {
                            var justChecked = checkbox.prop("checked");
                            var checkCount = (justChecked) ? 1 : -1;
                            for (i = 0; i < selector.options.length; i++) {
                                if (selector.options[i].selected) checkCount += 1;
                            }
                        }
                      });
                   }
               });
               

           }
    </script>
    <script type="text/javascript">
        $(document).ready(function () {

            $("#TypeProduct").dropdownchecklist({ icon: {}, width: 350, explicitClose: '...X', forceMultiple: true
            , onComplete: function (selector) {
                var values = "";
                for (i = 0; i < selector.options.length; i++) {
                    if (selector.options[i].selected && (selector.options[i].value != "")) {
                        if (values != "") {
                            values += ",";
                            values += selector.options[i].value;
                        }
                        else {
                            values += selector.options[i].value;
                            values += ",";
                        }
                    }
                }

                if (document.all || document.getElementById) {
                    document.getElementById('ArrTypeProductID').value = values;
                }
                else {
                    document.getElementById('ArrTypeProductID').setAttribute("value", values);
                }

                //Load Product combox
                getProduct(values);
            }
            , onItemClick: function (checkbox, selector) {
                var justChecked = checkbox.prop("checked");
                var checkCount = (justChecked) ? 1 : -1;
                for (i = 0; i < selector.options.length; i++) {
                    if (selector.options[i].selected) checkCount += 1;
                }
            }
            });


        
        });
    </script>
    <script type="text/javascript">
        function ChoiceTypeDiscount(dropDownList) {
            var selectedReport = dropDownList.options[dropDownList.selectedIndex];
            if (selectedReport.value == "true") {
                if (document.all || document.getElementById) {
                    document.getElementById('DiscountValue').style.display = "none";
                    document.getElementById('DiscountPercent').style.display = "";
                    document.getElementById('lbDiscountValue').style.display = "none";
                    document.getElementById('lbDiscountPercent').style.display = "";
                }
                else {
                    document.getElementById('DiscountValue').setAttribute("display", "none");
                    document.getElementById('DiscountPercent').setAttribute("display", "");
                    document.getElementById('lbDiscountValue').style.display = "none";
                    document.getElementById('lbDiscountPercent').style.display = "";
                }
            }
            else if (selectedReport.value == "false") {
                if (document.all || document.getElementById) {
                    document.getElementById('DiscountValue').style.display = "";
                    document.getElementById('DiscountPercent').style.display = "none";
                    document.getElementById('lbDiscountValue').style.display = "";
                    document.getElementById('lbDiscountPercent').style.display = "none";
                }
                else {
                    document.getElementById('DiscountValue').setAttribute("display", "");
                    document.getElementById('DiscountPercent').setAttribute("display", "none");
                    document.getElementById('lbDiscountValue').style.display = "none";
                    document.getElementById('lbDiscountPercent').style.display = "";
                }
            }
        }
 
    </script> 
    <script type="text/javascript">
        $(function () {
            $("#StartDate").datepicker({ dateFormat: 'dd/mm/yy' });
            $("#EndDate").datepicker({ dateFormat: 'dd/mm/yy' });
        });
	</script>
     <% Html.EnableClientValidation(); %> 
         <% using (Html.BeginForm((bool)ViewData["IsAdd"] ? "SaveAddDiscount" : "SaveEditDiscount", "Stock", FormMethod.Post, new { siteGuid = "sendFileForm", language = "sendFileForm", id = "sendFileForm", enctype = "multipart/form-data" }))
            {%>

            <div class="clear"></div>
       
        <div class="box ">
		    <h2 class="box-header"><%=(bool)ViewData["IsAdd"] ? "Tạo giá mới" : "Sửa giá" %></h2>
		    <div class="box-content">

                <label class="form-label"> Ngày bắt đầu </label>
                 <%=Html.TextBoxFor(m=>m.StartDate,new { @class = "form-field datepicker"}) %> <span style="color:Red;font-weight:bold"> <%= Html.ValidationMessageFor(m => m.StartDate)%> </span>

                 <label class="form-label"> Ngày kết thúc </label>
                 <%=Html.TextBoxFor(m=>m.EndDate,new { @class = "form-field datepicker"}) %>

                <label class="form-label"> Loại triết khấu </label>
                <%
                    List<SelectListItem> statusSearch = new List<SelectListItem>();
                    statusSearch.AddRange(new SelectListItem[] { 
                    new SelectListItem{ Text = "Phần trăm (%)", Value = "true" },
                    new SelectListItem{ Text = "Giá trị", Value = "false" }
                });
                %>

                <%=Html.DropDownListFor(m => m.TypeDiscounts, statusSearch, new { onchange = "ChoiceTypeDiscount(this);" })%>
                
                 <%--<label class="form-label"> Discount </label>--%>
                 <%= Html.TextBoxFor(m => m.DiscountPercent, new { @class = "form-field small" })%>
                 <%= Html.TextBoxFor(m=>m.DiscountValue, new { @class="form-field small", @Style="display:none;" }) %>
                 <label id="lbDiscountPercent">Phần trăm(%)</label>
                 <label id="lbDiscountValue" style="display:none">Giá trị</label>

                   
                 <label class="form-label"> Mô tả </label>
                 <%= Html.TextAreaFor(m => m.Description, new { @class = "form-field half" })%>
                 
                 <label class="form-label"> Trạng thái </label>
                 <%if (Model.Status == true)
                   {
                   %>
                        <%=Html.CheckBox("Status", true)%>  Kích hoạt
                   <%
                     }
                   else
                   {
                       if ((bool)ViewData["IsAdd"])
                       {
                       %>
                        <%=Html.CheckBox("Status", true)%>  Kích hoạt
                       <%
                       }
                       else
                       { 
                       %>
                        <%=Html.CheckBox("Status", false)%>  Kích hoạt
                       <%
                       }
                    
                   } 
                    %>    
                    
                 <label class="form-label">Lựa chọn danh mục sản phẩm </label>
                 <%= Html.DropDownList("TypeProduct", (MultiSelectList)ViewData["ListTypeProductDrop"], new { @multiple = "multiple" })%> 
                 <span style="color:Red;font-weight:bold">
                 <%= Html.ValidationMessageFor(m => m.ArrTypeProductID) %>
                 </span>
                 <%=Html.TextBoxFor(m=>m.ArrTypeProductID,new {@Style="display:none"}) %>
                 <%=Html.HiddenFor(m=>m.DiscountsID) %>
                 <label class="form-label">Chọn sản phẩm </label>
                 <select id="ProductDrop" style="width:355px">  <%= Html.ValidationMessageFor(m => m.ArrProductID) %>                  
                 </select>

                 

                 <%=Html.TextBoxFor(m => m.ArrProductID, new {@Style="display:none" })%>
                 <p>
                <%=ViewData["Result"]%>
                </p>
                    
                  <input type="submit" value="" class="button white_input save_input " style="width: 74px;height: 28px; float:left; margin-right:10px;"/> <!--Button Save-->
                  <a class="button white" href="javascript:history.back();"><span class="icon_text cancel"></span>Đóng</a> <!--Button Close-->
                 <%
                    if ((bool)ViewData["IsAdd"])
                    {

                    }
                    else
                    { 
                    %> 
                        <%--<%= Html.ActionLink("Properties", "", "Stock", new { id = Model.ProductID }, new { @class = "button themed" })%>--%>   
                    <%
                    }  
                 %>
                    
                 
	        </div>
	    </div>
        <div class="clear"></div>

            <% } %>

    <script type="text/javascript">
        var selecteds = document.getElementById("ArrTypeProductID").value;
        var combox = document.getElementById("TypeProduct");
        var arrSeleteds = selecteds.split(",");
        for (i = 0; i < combox.options.length; i++) {
            for (j = 0; j < arrSeleteds.length; j++) {
                if (combox.options[i].value == arrSeleteds[j]) {
                    combox.options[i].selected = true;
                }
            }

        }

    </script>
    <script type="text/javascript">
        var selecteds = document.getElementById("ArrProductID").value;
        var combox = document.getElementById("ProductDrop");
        var arrSeleteds = selecteds.split(",");
        for (i = 0; i < combox.options.length; i++) {
            for (j = 0; j < arrSeleteds.length; j++) {
                if (combox.options[i].value == arrSeleteds[j]) {
                    combox.options[i].selected = true;
                }
            }

        }

    </script>
</asp:Content>
